package com.tanhua.server.controller;

import com.tanhua.domain.vo.RecommendQueryVo;
import com.tanhua.domain.vo.TodayBestVo;
import com.tanhua.server.service.ExploreService;
import com.tanhua.server.service.TodayBestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

@RestController
@RequestMapping("tanhua")
@Slf4j
public class TodayBestController {
    @Autowired
    private TodayBestService todayBestService;

    //注入左滑右滑业务层
    @Autowired
    private ExploreService exploreService;

    /**
     * 接口名称：今日佳人
     * 接口路径：GET/tanhua/todayBest
     * 需求描述：查询缘分值最高的用户。 首页 进入佳人
     */
    @GetMapping("todayBest")
    public ResponseEntity<Object> todayBest(){
        return todayBestService.queryTodayBest();
    }

    /**
     * 接口名称：推荐朋友
     * 接口路径：GET/tanhua/recommendation
     * 需求描述：首页 查询推荐用户分页列表
     */
    @GetMapping("recommendation")
    public ResponseEntity<Object> recommendation(RecommendQueryVo vo){
        return todayBestService.queryRecommendation(vo);
    }

    /**
     * 接口名称：佳人信息
     * 接口路径：GET/tanhua/:id/personalInfo
     */
    @GetMapping("{id}/personalInfo")
    public ResponseEntity<Object> queryPersonalInfo(
            @PathVariable("id") Long recommendUserId){
        return todayBestService.queryPersonalInfo(recommendUserId);
    }

    /**
     * 接口名称：查询陌生人问题
     * 接口路径：GET/tanhua/strangerQuestions
     */
    @GetMapping("strangerQuestions")
    public ResponseEntity<Object> strangerQuestions(Long userId){
        return todayBestService.strangerQuestions(userId);
    }

    /**
     * 接口名称：回复陌生人问题
     * 接口路径：POST/tanhua/strangerQuestions
     */
    @PostMapping("strangerQuestions")
    public ResponseEntity<Object> replyQuestion(
            @RequestBody Map<String,String> map){
        Long userId = Long.parseLong(map.get("userId"));
        String reply = map.get("reply");
        return todayBestService.replyQuestion(userId,reply);
    }


    /**
     * 接口名称：搜附近
     * 接口路径：GET/tanhua/search
     */
    @GetMapping("search")
    public ResponseEntity<Object> searchNear(String gender,Long distance){
        return todayBestService.searchNear(gender,distance);
    }


    /**
     * 探花-左滑右滑
     * GET/tanhua/cards
     * @return
     */
    @GetMapping("cards")
    public ResponseEntity<Object> explore() throws InvocationTargetException, IllegalAccessException {
        log.info("进入左滑右滑");
        return exploreService.explore();
    }

    /**
     * 探花-喜欢
     * GET/tanhua/:id/love
     * @param loveId 喜欢的用户id
     * @return
     */
    @GetMapping("/{id}/love")
    public ResponseEntity<Object> love(@PathVariable("id")Long loveId){
        log.info("探花-喜欢");
        return exploreService.love(loveId);
    }

    /**
     * 探花-不喜欢
     * GET/tanhua/:id/unlove
     * @param unLoveId 不喜欢的用户id
     * @return
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity<Object> unLove(@PathVariable("id")Long unLoveId){
        log.info("探花-不喜欢");
        return exploreService.unLove(unLoveId);
    }
}
